function findRowCol(tile,x,y) {
    var coordX, coordY;
    var result = {
        row: null,
        col: null
    }

    if(tile != undefined) {
        coordX = tile.x + (defaultTileWidth / 2);
        coordY = tile.y + (defaultTileHeight / 2);
    }else {
        coordX = x - (camera.x + canvasOffset.left);
        coordY = y - (camera.y + canvasOffset.top);
    }

    var gridOffsetX = (canvas.width / 2) - (defaultTileWidth / 2);

    result.col = ((gridOffsetX + coordY * 2) - coordX) / 2;
    result.row = ((coordX + result.col) - defaultTileHeight) - gridOffsetX;
    result.col = Math.round(result.col / defaultTileHeight);
    result.row = Math.round(result.row / defaultTileHeight);

    return result;
}

function findTileByRowCol(row,col) {
    try {
        return tileMap[row][col]
    } catch (e) {
        return false;
    }
}

function findXY(row,col, camCoords) {
    var result = {
        x: null,
        y: null
    };

    //if the offset of the camera is needed
    try {
        if(camCoords){
            result.x = tileMap[row][col].x + camera.x;
            result.y = tileMap[row][col].y + camera.y;
        }
        else{
            result.x = tileMap[row][col].x;
            result.y = tileMap[row][col].y;
        }
    } catch(e) {
        throw e;
    }

    return result;
}

function findCurHeroTile(hero,asRowCol) {
    if(asRowCol) {

        return findRowCol(hero.path.steps[0]);
    }
    else
        return hero.path.steps[0];
}

//NOT CALLED FOR NOW
function generateRdmElemOnGrid() {
    var rndRow = Math.floor(Math.random() * grid.width);
    var rndCol = Math.floor(Math.random() * grid.height);

    //HEALTH STATE RANDOMIZER
    var rndState = Math.floor(Math.random() * 5);
    switch(rndState) {
        case 0:
            tileMap[rndRow][rndCol].healthLevel = HEALTH.GOOD;
            break;
        case 1:
            tileMap[rndRow][rndCol].healthLevel = HEALTH.MEDIUM;
            break;
        case 2:
            tileMap[rndRow][rndCol].healthLevel = HEALTH.AVERAGE;
            break;
        case 3:
            tileMap[rndRow][rndCol].healthLevel = HEALTH.LOW;
            break;
        case 4:
            tileMap[rndRow][rndCol].healthLevel = HEALTH.BAD;
            break;
    }

    //TILE PROPERTY RANDOMIZER
    var rndProperty = Math.floor(Math.random() * 3);
    switch(rndProperty) {
        case 0:
            tileMap[rndRow][rndCol].img = tile_neutral;
            break;
        case 1:
            tileMap[rndRow][rndCol].img = tile_owned;
            break;
        case 2:
            tileMap[rndRow][rndCol].img = tile_enemy;
            break;
    }
}